//
//  EvaluateViewController.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/8/17.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "EvaluateViewController.h"
#import <TTGTagCollectionView/TTGTextTagCollectionView.h>
#import "CallDataLogic.h"
@interface EvaluateViewController ()
@property(nonatomic, strong) TTGTextTagCollectionView *tagView;
@property(nonatomic, strong) CallDataLogic *logic;
@property(nonatomic, strong) QMUIFillButton *submiteButton;
@end

@implementation EvaluateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView *bgImgView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    bgImgView.image = [UIImage imageNamed:@"about_back"];
    [self.view addSubview:bgImgView];
    
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = self.view.bounds;
//    effectView.frame = CGRectMake(0, 0, bgImgView.frame.size.width * 0.5, bgImgView.frame.size.height);
    [bgImgView addSubview:effectView];
    
    
    self.tagView = [[TTGTextTagCollectionView alloc] init];
    [self.view addSubview:self.tagView];
    
    //提交按钮
    self.submiteButton = [[QMUIFillButton alloc] initWithFillColor:MainColor2 titleTextColor:KWhiteColor];
    [self.submiteButton addTarget:self action:@selector(handleSubmitEvent) forControlEvents:UIControlEventTouchUpInside];
    [self.submiteButton setTitle:ASLocalizedString(@"完成")forState:UIControlStateNormal];
    [self.view addSubview:self.submiteButton];
    
    [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(kTopHeight);
        make.left.equalTo(self.view).offset(10);
        make.right.equalTo(self.view).offset(-10);
        make.bottom.equalTo(self.view).offset(-130);
    }];
    
    [self.submiteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).offset(-40);
        make.width.equalTo(self.view).offset(-80);
        make.height.equalTo(@40);
        make.centerX.equalTo(self.view);
    }];
    
    _logic = [[CallDataLogic alloc] init];
    [_logic getEvaluateListBlock:^(id selfPtr) {
        for (EvaluateModel *model in selfPtr) {
            TTGTextTagConfig *tagConfig = [[TTGTextTagConfig alloc] init];
            tagConfig.tagTextColor = MainColor;
            tagConfig.tagSelectedBackgroundColor = MainColor;
            tagConfig.tagBackgroundColor = KClearColor;
            tagConfig.tagShadowRadius = 0;
            tagConfig.tagBorderWidth = 1;
            tagConfig.tagBorderColor = MainColor2;
            tagConfig.tagShadowColor = KClearColor;
            tagConfig.tagCornerRadius = 12;
            tagConfig.tagSelectedCornerRadius = 12;
            tagConfig.tagTextFont = DEFAULT_FONT(14);
            tagConfig.tagExtraSpace = CGSizeMake(10, 10);
            tagConfig.extraData = selfPtr;
            [self.tagView addTag:model.label_name withConfig:tagConfig];

        }
    }];
    
    self.view.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.2];
}

- (void)handleSubmitEvent {
    NSArray *allSelectTag = self.tagView.allSelectedTags;
    NSString *postTags = @"";
    for (int i=0; i<allSelectTag.count; i++) {
        NSString *tag = allSelectTag[i];
        if(i==0)
        {
            postTags = tag;
        }
        else
        {
            postTags = [NSString stringWithFormat:@"%@-%@",postTags,tag];
        }
    }
    
    [_logic postEvaluateWithString:postTags AndChannelId:self.channel_id andToUid:self.to_user_id Block:^(id selfPtr) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
